/**  
 * All rights Reserved, Designed By <a href="www.itttq.com" target="_blank">www.itttq.com</a>
 * @date:   2018-01-6 11:42:21
 * @Copyright: 2017 <a href="www.itttq.com" target="_blank">www.itttq.com</a> Inc. All rights reserved. 
 */
package com.itttq.gshop.admin.controller.sys;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.itttq.gshop.admin.controller.GenericController;
import com.itttq.gshop.domain.to.PageParamTo;
import com.itttq.gshop.domain.to.ResultPageTo;
import com.itttq.gshop.domain.po.SysLogsPo;
import com.itttq.gshop.generic.connector.ISysLogsConnector;

@RestController
@RequestMapping("sys/logs")
public class SysLogsController extends GenericController {
	private static final long serialVersionUID = 187162096427391109L;
	@Autowired
	private ISysLogsConnector sysLogsConnector;
	
	/**
	 * 根据条件查询SysLogsPo对象，并分页
	 * 
	 * @param sysLogs
	 * @param request
	 * @return
	 * @Author 迷蝶
	 * @return ModelAndView
	 */
	@RequestMapping("logss.html")
	public ModelAndView getSysLogss(SysLogsPo sysLogs, HttpServletRequest request) {
		ModelAndView mv = new ModelAndView("/sys/logss");
		PageParamTo ppt = null == request ? new PageParamTo() : getPageParam(request);
		sysLogs.setStart(ppt.getStart());
		sysLogs.setSize(ppt.getSize());
		ResultPageTo<SysLogsPo> rpt = sysLogsConnector.getSysLogss(sysLogs);
		this.getPageMv("logss", mv, rpt);
		mv.addObject("logs", sysLogs);
		return mv;
	}

	
	/**
	 * 跳转到新增页面
	 * @return
	 */
	@RequestMapping("add.html")
	public ModelAndView addSysLogs() {
		ModelAndView mv = new ModelAndView("/sys/logsAdd");
		
		return mv;
	}
	/**
	 * 跳转到查看页面
	 * @param id
	 * @return
	 */
	@RequestMapping("view/{id}.html")
	public ModelAndView viewSysLogs(@PathVariable("id") Integer id) {
		ModelAndView mv = addSysLogs();
		if(id != null) {
			mv.addObject("logs", sysLogsConnector.getSysLogs(id));
		}
		mv.addObject("op", "view");
		return mv;
	}
	/**
	 * 跳转到编辑页面
	 * @param id
	 * @return
	 */
	@RequestMapping("edit/{id}.html")
	public ModelAndView editSysLogs(@PathVariable("id") Integer id) {
		ModelAndView mv = viewSysLogs(id);
		mv.addObject("op", "edit");
		return mv;
	}
	
	/**
	 * 保存SysLogsPo对象，无ID则新增，有ID则更新
	 * 
	 * @param sysLogs
	 * @return
	 * @Author 迷蝶
	 * @return ModelAndView
	 */
	@RequestMapping("save.html")
	public ModelAndView saveSysLogs(SysLogsPo sysLogs) {
		sysLogsConnector.saveSysLogs(sysLogs);
		return getSysLogss(new SysLogsPo(), null);
	}

	/**
	 * 根据ID删除SysLogsPo对象
	 * 
	 * @param id
	 * @return
	 * @Author 迷蝶
	 * @return ModelAndView
	 */
	@RequestMapping("del/{id}.html")
	@ResponseBody
	public ModelAndView delSysLogs(@PathVariable("id") Integer id) {
		if(id != null) {
			sysLogsConnector.delSysLogs(id);
		}
		return getSysLogss(new SysLogsPo(), null);
	}
}